package com.payroll.security;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Category;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.payroll.action.PayrollActionForm;
import com.payroll.util.PayrollConstants;

public class LogonForm extends PayrollActionForm{
	private String username = null;
	private String password = null;

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		Category cat = Category.getInstance(this.getClass().getName()
                + ".validate");

        ActionErrors m_errors = new ActionErrors();

        if (this.getAction().equals(PayrollConstants.LOGON_ACTION)
                || getAction().equals(PayrollConstants.CHANGE_PW_ACTION)) {
            // validate that the appropriate fields are filled in. Only on
            // manual LOGON
            if (this.getUsername() == null || this.getUsername().length() < 1) {
                m_errors
                        .add("User Name", new ActionError("100021", "Username"));
            }

            if (this.getPassword() == null || this.getPassword().length() < 1) {
                m_errors.add("Password", new ActionError("100021", "Password"));

            }
        }
       /* if (getAction().equals(SacwisConstants.CHANGE_PW_ACTION)) {
            if (this.getNewPassword() == null
                    || this.getNewPassword().length() < 1) {
                m_errors.add("New Password", new ActionError("207"));
            }
            if (this.getNewPasswordReenter() == null
                    || getNewPasswordReenter().equals(getNewPassword()) == false) {
                m_errors.add("Reenter New Password", new ActionError("208"));
            }
        }*/

        return m_errors;
}

	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}
